package com.spar.openprojects.shared.rowmapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import com.spar.openprojects.shared.Member;
import com.spar.openprojects.shared.OrderItem;
import com.sql.database.IRowMapper;

public class OrderItemRowMapper implements IRowMapper {

	@Override
	public OrderItem mapRow(ResultSet rs) throws SQLException {
		OrderItem orderItem = new OrderItem();

		orderItem.setId(rs.getInt("i.id"));
		orderItem.setOrderId(rs.getInt("i.order_id"));
		orderItem.setType(rs.getInt("i.orderitem_type_id"));
		orderItem.setAmount(rs.getDouble("i.amount"));
		if (rs.getTimestamp("i.date") != null) {
			orderItem.setDate(new Date(rs.getTimestamp("i.date").getTime()));
		}
		orderItem.setLink(rs.getString("i.link"));
		orderItem.setNumber(rs.getString("i.number"));

		if (rs.getTimestamp("i.date_approval") != null) {
			orderItem.setReleaseDate(new Date(rs
					.getTimestamp("i.date_approval").getTime()));
		}
		Member updateMember = new Member();
		updateMember.setNumber(rs.getString("i.member_number_updated"));
		orderItem.setUpdateMember(updateMember);
		Member createMember = new Member();
		createMember.setNumber(rs.getString("i.member_number_created"));
		orderItem.setCreateMember(createMember);
		return orderItem;
	}

}
